[#include "/includes/_layout.html"/]
<style type="text/css">
</style>
[@layout]
<div class="wrapper wrapper-content">
<div class="row animated fadeInLeft">
	[#include "/includes/menu-agent.html" /]
	<div class="col-sm-11">
		<div class="row content-tabs">
			<nav class="page-tabs J_menuTabs">
		       <div class="page-tabs-content" style="margin-left: 0px;">
		           <a href="${webctx}/agent/aduit" class="J_menuTab">分销商审核</a>
			       <a href="${webctx}/agent" class="J_menuTab">分销商</a>
			       <a href="${webctx}/agent/rank" class="J_menuTab active">分销商等级</a>
		       </div>
		   	</nav>
		</div>
		
		<div class="ibox float-e-margins">
			<div class="ibox-title row">
				<h5><small><a href="${webctx}/agent/rank">《返回列表</a></small></h5>
			</div>
			<div class="row ibox-content active_statistics col-sm-9">
				<div class="title_query padtop">
					<form id="rankForm" action="" method="post" class="form-horizontal">
						<input type="hidden" name="id" id="rand_id" value="${rand.id}"/>
						<div class="form-group">
				            <label class="col-md-2 control-label">等级名称<span style="color: red;"><em>*</em></span></label>
				            <div class="col-md-3" id="error_rank_name">
				                <input id="rank_name" name= "rank_name" value="${rand.rank_name}" maxlength="20" type="text" class="form-control" >
				                <label class="control-label" for="rank_name"></label>
				            </div>
				        </div>
				        
				        <div class="form-group">
				            <label class="col-md-2 control-label">一级佣金占比
				            <span style="color: red;"><em>*</em></span></label>
				            <div class="col-md-2 " id="error_first_rate">
				            <div class="input-group m-b">
				                <input id="first_rate" name= "first_rate" value="${rand.first_rate}" maxlength="20" type="text" class="form-control" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')">
				                <span class="input-group-addon">%</span> 
				                </div>
				                <label class="control-label" for="first_rate"></label>
				            </div>
				             <label class="col-md-2 control-label">二级佣金占比
				            <span style="color: red;"><em>*</em></span></label>
				            <div class="col-md-2" id="error_second_rate">
				             <div class="input-group m-b">
				                <input id="second_rate" name="second_rate" value="${rand.second_rate}" maxlength="20" type="text" class="form-control" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')">
				                 <span class="input-group-addon">%</span> 
				               </div>
				                <label class="control-label" for="second_rate"></label>
				            </div>
				            
				            <label class="col-md-2 control-label">三级佣金占比
				            <span style="color: red;"><em>*</em></span></label>
				            <div class="col-md-2" id="error_third_rate">
				            <div class="input-group m-b">
				                <input id="third_rate" name="third_rate" value="${rand.third_rate}" maxlength="20" type="text" class="form-control" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')">
				                <span class="input-group-addon">%</span> 
				              </div>
				                <label class="control-label" for="third_rate"></label>
				            </div>
				        </div>
				        <div class="form-group">
				            <label class="col-md-2 control-label">等级奖励金额
				            <i class="fa fa-question-circle" onmouseout="layer.closeAll();" onmouseover="layer.tips('升到此等级奖励金额，只有首次升级到此等级才获取奖励。', this, {tips: [1, '#3595CC'],time: 0});"></i>
				            <span style="color: red;"><em>*</em></span></label>
				            <div class="col-md-2" id="error_reward_value">
				                <input id="reward_value" name="reward_value" value="${rand.reward_value}" maxlength="20" type="text" class="form-control" onkeyup="this.value=this.value.replace(/[^\d]/g,'')">
				                <label class="control-label" for="reward_value"></label>
				            </div>
				        </div>
				        <div class="form-group">
				            <label class="col-md-2 control-label">每日提现次数
				            <span style="color: red;"><em>*</em></span></label>
				            <div class="col-md-2" id="error_get_cash_time">
				                <input id="get_cash_time" name="get_cash_time" value="${rand.get_cash_time}" maxlength="20" type="text" class="form-control" onkeyup="this.value=this.value.replace(/[^\d]/g,'')">
				                <label class="control-label" for="get_cash_time"></label>
				            </div>
				            <label class="col-md-2 control-label">每次提现上限
				            <span style="color: red;"><em>*</em></span></label>
				            <div class="col-md-2" id="error_get_cash_limit">
				                <input id="get_cash_limit" name="get_cash_limit" value="${rand.get_cash_limit}" maxlength="20" type="text" class="form-control" onkeyup="this.value=this.value.replace(/[^\d]/g,'')">
				                <label class="control-label" for="get_cash_limit"></label>
				            </div>
				        </div>
				        <div class="form-group">
				            <label class="col-md-2 control-label">当月推广人数
				            <i class="fa fa-question-circle" onmouseout="layer.closeAll();" onmouseover="layer.tips('满足直属下级用户数量（自动升级条件，没有达到会自动降级）。', this, {tips: [1, '#3595CC'],time: 0});"></i>
				            <span style="color: red;"><em>*</em></span></label>
				            <div class="col-md-2" id="error_children_count">
				                <input id="children_count" name="children_count" value="${rand.children_count}" maxlength="20" type="text" class="form-control" onkeyup="this.value=this.value.replace(/[^\d]/g,'')">
				                <label class="control-label" for="children_count"></label>
				            </div>
				        </div>
				        <div class="form-group">
				            <label class="col-md-2 control-label">当月累计佣金
				            <i class="fa fa-question-circle" onmouseout="layer.closeAll();" onmouseover="layer.tips('当月累计获取佣金（自动升级条件，没有达到会自动降级）。', this, {tips: [1, '#3595CC'],time: 0});"></i>
				            <span style="color: red;"><em>*</em></span></label>
				            <div class="col-md-2" id="error_total_commission">
				                <input id="total_commission" name="total_commission" value="${rand.total_commission}" maxlength="20" type="text" class="form-control" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')">
				                <label class="control-label" for="total_commission"></label>
				            </div>
				        </div>
				     <div class="panel-default">   
				    <div class="panel-footer" align="center">
				   	 	<button type="button" onclick="saveRank();" class="btn btn-success btn-sm">保存</button>
					</div>
					</div>
				     </form>
				 </div>
		   </div>  
		 </div>  
		   <div class="col-sm-3">
	    <div class="wrapper wrapper-content project-manager">
	        <h4>帮助说明</h4>
	        <ol>
	            <li>分销商可以建立等级体系，比如省级代理，市级代理，县级代理等</li>
	            <li>每一个等级可以设置对于的佣金分配比率</li>
	            <li>没有设置代理等级按系统佣金比率分配佣金</li>
	            <li>分销商可以按等级里面的条件进行自动升级降级，当然获取的佣金比率也会不同</li>
	            <li><font color="red">注意：一旦设置了分销商等级后，系统会根据等级条件自动判断该分销商是否满足，如果满足的话，就按该等级进行佣金分配</font></li>
	        </ol>
	    </div>
	</div>
	</div>
</div>
</div>
[/@layout]
<script type="text/javascript">
function saveRank(){
	var params={}, error = {};
	var rank_name = $("#rank_name").val(), first_rate=$("#first_rate").val()
	, second_rate = $("#second_rate").val(), third_rate = $("#third_rate").val(),reward_value = $("#reward_value").val()
	, get_cash_time = $("#get_cash_time").val(), get_cash_limit = $("#get_cash_limit").val(),children_count = $("#children_count").val()
	,total_commission = $("#total_commission").val(),rand_id = $("#rand_id").val();
	if($.trim(rank_name) =="") {error.error_rank_name = "等级不能为空"; } else {error.error_rank_name=""; params.rank_name = $.trim(rank_name);}
	if($.trim(first_rate) =="") {error.error_first_rate = "一级佣金占比不能为空"; } else {error.error_first_rate=""; params.first_rate = $.trim(first_rate);}
	if($.trim(second_rate) =="") {error.error_second_rate = "二级佣金占比不能为空"; } else {error.error_second_rate=""; params.second_rate = $.trim(second_rate);}
	if($.trim(third_rate) =="") {error.error_third_rate = "三级佣金占比不能为空"; } else {error.error_third_rate=""; params.third_rate = $.trim(third_rate);}
	if($.trim(reward_value) =="") {error.error_reward_value = "等级奖励金额不能为空"; } else {error.error_reward_value=""; params.reward_value = $.trim(reward_value);}
	if($.trim(get_cash_time) =="") {error.error_get_cash_time = "提现次数不能为空"; } else {error.error_get_cash_time=""; params.get_cash_time= $.trim(get_cash_time);}
	if($.trim(get_cash_limit) =="") {error.error_get_cash_limit = "提现上限不能为空"; } else {error.error_get_cash_limit=""; params.get_cash_limit = $.trim(get_cash_limit);}
	if($.trim(children_count) =="") {error.error_children_count = "用户数量不能为空"; } else {error.error_children_count=""; params.children_count = $.trim(children_count);}
	if($.trim(total_commission) =="") {error.error_total_commission = "获取佣金 不能为空"; } else {error.error_total_commission=""; params.total_commission = $.trim(total_commission);}
	params.id=rand_id;
	var hasError = false;
	for(var key in error){
		if(error[key]!=""){
			if(!hasError) hasError = true;
			$("#"+key).addClass("has-error");
			$("#"+key).find("label").text(error[key]);
		}else{
			$("#"+key).removeClass("has-error");
			$("#"+key).find("label").empty();
		}
	}
	//主表信息不完整，返回
	if(hasError) return false;
	$("#rankForm").mask("正在保存...");
	$.post(obz.ctx+"/agent/rank/saveRank", params, function(json) {
		if(json.code!=200){
			obz.error(json.msg, function(){
				$("#rankForm").unmask();
			});				
		}else{
			obz.msg('保存成功', function(){
				$("#rankForm").unmask();
				location.href="${webctx}/rank";
			});					
		}
	},"json");
}
</script>
<script>
Template.init("#menu-agent-first");
Template.initSecond("#menu-agent");
</script>